<?php

/**
 * 后台管理组验证器
 * @author  xiaobai
 * @date    2017-01-12
 */

namespace app\common\validate;

use think\Validate;

class Admin extends Validate
{
    
    protected $rule = [
        'account'   => 'require|alphaDash|min:3|max:25|unique:admin',
        'password'  => 'require|min:6|max:25',
        'nicename'  => 'require',
        'email'     => 'email|unique:admin',
        'mobile'    => 'mobile|unique:admin',
        'group_id'  => 'require|array',
        'captcha'   => 'require',
    ];

    protected $message = [
        'account.require'   => '登录账户不能为空',
        'account.alphaDash' => '登录账户只能是字母、数字、_和-',
        'account.min'       => '登录账户最少3个字符长度',
        'account.max'       => '登录账户不得超过25个字符',
        'account.unique'    => '此账户已存在',
        'password.require'  => '登录密码不能为空',
        'password.min'      => '密码长度最少为6个字符',
        'password.max'      => '密码长度不能超过25个字符',
        'nicename.require'  => '昵称不能为空',
        'email.email'       => '邮箱格式错误',
        'email.unique'      => '此邮箱已存在',
        'mobile.mobile'     => '手机格式错误',
        'mobile.unique'     => '手机号已经存在',
        'group_id.require'  => '所属管理组必须',
        'group_id.array'    => '所属管理组必须为数组',
        'captcha.require'   => '请输入验证码',
    ];

    protected $regex = [
        'mobile'    => "/1[34758]{1}\d{9}$/",
    ];

    protected $scene = [
        'add'   => ['account','password','nicename','email','mobile','group_id'],
        'edit'  => ['nicename','email','mobile','group_id','password'=>'requireWith:password|min:6|max:25'],
        'login' => ['account'=>'require','password'=>'require','captcha'],
    ];

}
